#!/usr/bin/python3
import main
import time
import datetime
from threading import Timer
from flask import Flask, request
import Pyconfig
import service.MainService
import DB
import json
import sys


def startgo():
    print('程序启动时刻：', time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    print("===============================监控提醒开始========================================")
    # 定期每天几时几分执行
    # 微报警外网数据推送给用户监控提醒
    # Timer(60, main.main_dqzx, (Pyconfig.YnDqsj.hh, Pyconfig.YnDqsj.mm,'webchat_touser_tx')).start()
    # 微报警内网数据推送至110指挥中心监控提醒
    # Timer(60, main.main_dqzx, (Pyconfig.YnDqsj.hh, Pyconfig.YnDqsj.mm,'webchat_to110_tx')).start()
    # 出入境内网数据推送至出入境总队监控提醒
    # Timer(60, main.main_dqzx, (Pyconfig.YnDqsj.hh, Pyconfig.YnDqsj.mm,'crj_tocrjglj_tx')).start()
    # 户政内网数据推送至户政总队监控提醒
    # Timer(60, main.main_dqzx, (Pyconfig.YnDqsj.hh, Pyconfig.YnDqsj.mm,'hz_tohzzd_tx')).start()

    # 监控内外网双边表的数据是否一致
    qsj = (datetime.datetime.now() - datetime.timedelta(minutes=10)).strftime("%Y-%m-%d %H:%M")
    qdsj = (datetime.datetime.now() - datetime.timedelta(days=3)).strftime("%Y-%m-%d %H:%M")
    print(qsj)
    ##早上提醒(8:20)
    Timer(60, main.main_dqzx_tb, (
        Pyconfig.YnDqsj.hh, Pyconfig.YnDqsj.mm, 'oi_wechat_chat',
        ' and changedate > \'' + qdsj + '\'' + ' and changedate<\'' + qsj + '\'',
        '微报警会话外到内',)).start()
    Timer(60, main.main_dqzx_tb, (
        Pyconfig.YnDqsj.hh, Pyconfig.YnDqsj.mm, 'oi_wechat_alarm',
        ' and createdate > \'' + qdsj + '\'' + ' and createdate < \'' + qsj + '\'',
        '微报警信息外到内',)).start()
    Timer(60, main.main_dqzx_tb, (
        Pyconfig.YnDqsj.hh, Pyconfig.YnDqsj.mm, 'io_wechat_chat',
        ' and changedate > \'' + qdsj + '\'' + ' and changedate<\'' + qsj + '\'',
        '微报警会话内到外',)).start()
    Timer(60, main.main_dqzx_tb, (
        Pyconfig.YnDqsj.hh, Pyconfig.YnDqsj.mm, 'oi_crj_bills',
        ' and create_time > \'' + qdsj + '\'' + ' and create_time <\'' + qsj + '\'',
        '出入境信息外到内',)).start()
    Timer(60, main.main_dqzx_tb, (
        Pyconfig.YnDqsj.hh, Pyconfig.YnDqsj.mm, 'oi_hz_bills',
        ' and create_time > \'' + qdsj + '\'' + 'and create_time<\'' + qsj + '\'',
        '户政信息外到内',)).start()
    ##中午提醒(13:20)
    Timer(60, main.main_dqzx_tb, (
        13,20, 'oi_wechat_chat',
        ' and changedate > \'' + qdsj + '\'' + ' and changedate<\'' + qsj + '\'',
        '微报警会话外到内',)).start()
    Timer(60, main.main_dqzx_tb, (
        13, 20, 'oi_wechat_alarm',
        ' and createdate > \'' + qdsj + '\'' + ' and createdate < \'' + qsj + '\'',
        '微报警信息外到内',)).start()
    Timer(60, main.main_dqzx_tb, (
        13, 20, 'io_wechat_chat',
        ' and changedate > \'' + qdsj + '\'' + ' and changedate<\'' + qsj + '\'',
        '微报警会话内到外',)).start()
    Timer(60, main.main_dqzx_tb, (
        13, 20, 'oi_crj_bills',
        ' and create_time > \'' + qdsj + '\'' + ' and create_time <\'' + qsj + '\'',
        '出入境信息外到内',)).start()
    Timer(60, main.main_dqzx_tb, (
        13, 20, 'oi_hz_bills',
        ' and create_time > \'' + qdsj + '\'' + 'and create_time<\'' + qsj + '\'',
        '户政信息外到内',)).start()

    ##下午提醒(18:10)
    Timer(60, main.main_dqzx_tb, (
        18,10, 'oi_wechat_chat',
        ' and changedate > \'' + qdsj + '\'' + ' and changedate<\'' + qsj + '\'',
        '微报警会话外到内',)).start()
    Timer(60, main.main_dqzx_tb, (
        18, 10, 'oi_wechat_alarm',
        ' and createdate > \'' + qdsj + '\'' + ' and createdate < \'' + qsj + '\'',
        '微报警信息外到内',)).start()
    Timer(60, main.main_dqzx_tb, (
        18, 10, 'io_wechat_chat',
        ' and changedate > \'' + qdsj + '\'' + ' and changedate<\'' + qsj + '\'',
        '微报警会话内到外',)).start()
    Timer(60, main.main_dqzx_tb, (
        18, 10, 'oi_crj_bills',
        ' and create_time > \'' + qdsj + '\'' + ' and create_time <\'' + qsj + '\'',
        '出入境信息外到内',)).start()
    Timer(60, main.main_dqzx_tb, (
        18, 10, 'oi_hz_bills',
        ' and create_time > \'' + qdsj + '\'' + 'and create_time<\'' + qsj + '\'',
        '户政信息外到内',)).start()

    ##晚上提醒(20:10)
    Timer(60, main.main_dqzx_tb, (
        20, 10, 'oi_wechat_chat',
        ' and changedate > \'' + qdsj + '\'' + ' and changedate<\'' + qsj + '\'',
        '微报警会话外到内',)).start()
    Timer(60, main.main_dqzx_tb, (
        20, 10, 'oi_wechat_alarm',
        ' and createdate > \'' + qdsj + '\'' + ' and createdate < \'' + qsj + '\'',
        '微报警信息外到内',)).start()
    Timer(60, main.main_dqzx_tb, (
        20, 10, 'io_wechat_chat',
        ' and changedate > \'' + qdsj + '\'' + ' and changedate<\'' + qsj + '\'',
        '微报警会话内到外',)).start()
    Timer(60, main.main_dqzx_tb, (
        20, 10, 'oi_crj_bills',
        ' and create_time > \'' + qdsj + '\'' + ' and create_time <\'' + qsj + '\'',
        '出入境信息外到内',)).start()
    Timer(60, main.main_dqzx_tb, (
        20, 10, 'oi_hz_bills',
        ' and create_time > \'' + qdsj + '\'' + 'and create_time<\'' + qsj + '\'',
        '户政信息外到内',)).start()

    # 测试网站
    # Timer(1, main.ce_yngov, ()).start()

    # 微服务心跳监控
    # Timer(1, main.ms_version, ("apphub/version",)).start()
    # Timer(1, main.ms_version, ("base/pcc",)).start()
    # Timer(1, main.ms_version, ("consult/version",)).start()
    # Timer(1, main.ms_version, ("matter/version",)).start()
    # Timer(1, main.ms_version, ("member/version",)).start()
    # Timer(1, main.ms_version, ("message/version",)).start()
    # Timer(1, main.ms_version, ("news/version",)).start()
    # Timer(1, main.ms_version, ("query/version",)).start()
    # Timer(1, main.ms_version, ("storage/pcc",)).start()
    # Timer(1, main.ms_version, ("task",)).start()
    # Timer(1, main.ms_version, ("webchat",)).start()
